<template>
	<view >
		<view class="head_bg" style="height:200rpx;">
			<view class="ele_title_left padding-left-sm padding-bottom-xs">
				<view class="ele_title_inner padding-xs">
					<image class="ele_address_img" src="../../common/img/gongsi_bai.png" mode=""></image>
				    <text class="text-white">{{info.residential_quarters_name}}</text></view>
				<view class="ele_address padding-xs">
					<image class="ele_address_img" src="../../common/img/dizhi_bai.png" mode=""></image>
					<text class="text-white">{{info.residential_quarters_address}}</text>
				</view>
			</view>
		</view>
		<form @submit="formSubmit" @reset="">
			<view class="add_comm_title">套餐内容</view>
			<view class="add_box">
				<view class="add_inner">
					<view class="add_inner_text">套餐名称：</view>
					<input class="add_inner_input" type="text" v-model="form.package_name" 
					name="residential_quarters_name" value="" placeholder="请输入套餐名称" />
				</view>
				<view class="add_inner">
					<view class="add_inner_text">是否启用：</view>
					<switch @change="SwitchA" :class="form.is_enable==0?'checked':''" :checked="form.is_enable==0?true:false"></switch>
				</view>
				<radio-group class="block" @change="tclxChange">
					<view class="cu-form-group">
						<view class="title">套餐类型：</view>
						<view class="title">
							<text class=""><!-- 0 包周 1包月 2包季 3包年 -->
								<radio class='blue' :checked="form.package_type==0?true:false" style="transform:scale(0.8)" value="0"></radio>
								<text class="margin-left-xs text-sm ">包周</text>
							</text>
							<text class="margin-left-xs">
								<radio class='blue' :checked="form.package_type==1?true:false" style="transform:scale(0.8)" value="1"></radio>
								<text class="margin-left-xs text-sm">包月</text>
							</text>
							<text class="margin-left-xs">
								<radio class='blue' :checked="form.package_type==2?true:false" style="transform:scale(0.8)" value="2"></radio>
								<text class="margin-left-xs text-sm">包季</text>
							</text>
							<text class="margin-left-xs">
								<radio class='blue' :checked="form.package_type==3?true:false" style="transform:scale(0.8)" value="3"></radio>
								<text class="margin-left-xs text-sm">包年</text>
							</text>
						</view>
					</view>
				</radio-group>
				<radio-group class="block" @change="sffsChange">
					<view class="cu-form-group">
						<view class="title">收费方式：</view>
						<view class="title">
							<text class=""><!-- 0 按时长 1按次数 -->
								<radio class='blue' :checked="form.charging_method==0?true:false" style="transform:scale(0.8)" value="0"></radio>
								<text class="margin-left-xs text-sm ">按时长</text>
							</text>
							<text class="margin-left-xs">
								<radio class='blue' :checked="form.charging_method==1?true:false" style="transform:scale(0.8)" value="1"></radio>
								<text class="margin-left-xs text-sm">按次数</text>
							</text>
						</view>
					</view>
				</radio-group>
				<view class="add_inner">
					<view class="add_inner_text">套餐价格：</view>
					<input class="add_inner_input" type="text" v-model="form.package_price" 
					name="residential_quarters_name" value="" placeholder="请输入套餐价格" />
				</view>
				<view class="add_inner">
					<view class="add_inner_text">每日可充次数：</view>
					<input class="add_inner_input" type="text" v-model="form.user_num" 
					name="residential_quarters_name" value="" placeholder="请输入每日可充次数" />
				</view>
				<view class="add_inner">
					<view class="add_inner_text">限制次数或者小时：</view>
					<input class="add_inner_input" type="text" v-model="form.charging_num" 
					name="residential_quarters_name" value="" placeholder="请输入限制次数或者小时" />
				</view>
				<view class="add_inner">
					<view class="add_inner_text">单次充电时长：</view>
					<input class="add_inner_input" type="text" v-model="form.charging_time" 
					name="residential_quarters_name" value="" placeholder="请输入单次充电时长" />
				</view>
			</view>
			
			<button type="button" class="add_text_btn" @click="saveInfo">保存</button>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info:null,
				id:"",
				form:{
					is_enable:1,
					set_meal_guid:""
				}
			}
		},
		onLoad(options) {
			this.info=JSON.parse(options.info)
			if(options.id){
				this.id=options.id
			}
		},
		onShow() {
		    this.getdata();
		},
		methods: {
			getdata(){
				let that=this;
				that.http.tokenreq({
					url: 'setmeal/v1/getinfo',
					data:{"set_meal_guid":that.id}
				}).then((res) => {
					let e=res.data;
					if(e.code==0 && e.success){
						that.form=e.data;
					}
				})
			},
			SwitchA(e){
				if(e.detail.value){
					this.form.is_enable=0
				}else{
					this.form.is_enable=1
				}
			},
			tclxChange(e) {
				this.form.package_type = e.detail.value
			},
			sffsChange(e){
				this.form.charging_method = e.detail.value
			},
			saveInfo(){
				let title=""
				if(!this.form.package_name){
					title="请输入套餐名称"
				}
				if(!this.form.package_price){
					title="请输入套餐价格"
				}
				if(title){
					uni.showToast({
						icon: 'none',
					    title: title
					});
					return;
				}
				let that=this;
				this.form.residential_quarters_guid=this.info.residential_quarters_guid
				that.http.tokenreq({
					url:"setmeal/v1/edit",
					data:this.form
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						uni.showModal({
							content: e.message,
							showCancel:false,
							success: function (res) {
								if (res.confirm) {
									uni.redirectTo({
										url:'/pages/index/community_package?info='+JSON.stringify(that.info)
									})
								}
							}
						});
					}else{
						uni.showToast({
							icon: 'none',
						    title: e.message
						});
					}
				})
			}
		}
	}
</script>

<style>

</style>
